﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using WalkingTec.Mvvm.Core;
using System.Text.Json.Serialization;
using nERP.Model;
using nERP.Model.So;
using nERP.Model.Bas;
using nERP.Model.Wms;

namespace nERP.Model.Wms
{
    /// <summary>
    /// 销售出库
    /// </summary>
	[Table("SaleOutWarehouse")]
    [SoftKey(nameof(SaleOutWarehouse.SaleOutWarehouseCode))]
    [Display(Name = "_Model.SaleOutWarehouse")]
    public class SaleOutWarehouse : BasePoco,IPersistPoco,ITenant,IWorkflow
    {
        [Display(Name = "_Model._SaleOutWarehouse._SaleOutWarehouseCode")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Required(ErrorMessage = "Validate.{0}required")]
        [Comment("销售出库单号")]
        [CanNotEdit]
        public string SaleOutWarehouseCode { get; set; }
        [Display(Name = "_Model._SaleOutWarehouse._Sale")]
        [Comment("销售订单")]
        [NotMapped]
        public Sale Sale { get; set; }
        [Display(Name = "_Model._SaleOutWarehouse._Sale")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("销售订单")]
        public string SaleId { get; set; }
        [Display(Name = "_Model._SaleOutWarehouse._Customer")]
        [Comment("客户")]
        [NotMapped]
        public Customer Customer { get; set; }
        [Display(Name = "_Model._SaleOutWarehouse._Customer")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("客户")]
        public string CustomerId { get; set; }
        [Display(Name = "_Model._SaleOutWarehouse._InvoicesDate")]
        [Comment("单据日期")]
        public DateTime? InvoicesDate { get; set; }
        [Display(Name = "_Model._SaleOutWarehouse._InvoicesFile")]
        [Comment("单据附件")]
        public List<SaleOutWarehouseInvoicesFile> InvoicesFile { get; set; }
        [Display(Name = "_Model._SaleOutWarehouse._MakeUser")]
        [Comment("制单人")]
        [NotMapped]
        public FrameworkUser MakeUser { get; set; }
        [Display(Name = "_Model._SaleOutWarehouse._MakeUser")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("制单人")]
        public string MakeUserId { get; set; }
        [Display(Name = "_Model._SaleOutWarehouse._Status")]
        [Comment("单据状态")]
        public StatusTypeEnum? Status { get; set; }
        [Display(Name = "_Model._SaleOutWarehouse._Remark")]
        [StringLength(256, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("备注")]
        public string Remark { get; set; }
        [Display(Name = "_Model._SaleReturn._SaleOutWarehouse")]
        [InverseProperty("SaleOutWarehouse")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.So.SaleReturn.SaleOutWarehouseId))]
        public List<SaleReturn> SaleReturn_SaleOutWarehouse { get; set; }
        [Display(Name = "_Model._SaleOutWarehouseDetail._SaleOutWarehouse")]
        [InverseProperty("SaleOutWarehouse")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Wms.SaleOutWarehouseDetail.SaleOutWarehouseId))]
        public List<SaleOutWarehouseDetail> SaleOutWarehouseDetail_SaleOutWarehouse { get; set; }
        [Display(Name = "_Model._SaleOutWarehouse._IsValid")]
        [Comment("是否有效")]
        [Required(ErrorMessage = "Validate.{0}required")]
        public bool IsValid { get; set; } = true;
        [StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
        public string TenantCode { get; set; }

	}
    public class SaleOutWarehouseInvoicesFile : TopBasePoco, ISubFile
    {
        public Guid SaleOutWarehouseId { get; set; }
        public SaleOutWarehouse SaleOutWarehouse { get; set; }
        public Guid FileId { get; set; }
        public FileAttachment File { get; set; }
        public int Order { get; set; }
    }

}
